package Cinema;
import Cinema.DataLayer.DataManager;
import Cinema.DataLayer.DataPackage;
import Cinema.DataLayer.IDataManager;
import Cinema.DataLayer.XmlBackup;
import Exceptions.DataAccessException;
import Exceptions.XMLParsingException;
import GUIs.ClientUI;
import GUIs.ConnectionUI;
import GUIs.LoadingUI;


/**
 * The main Cinema System controller.
 * @author The Fuchtzeinsoft Team.
 *
 */
public class CinemaSystem{
	
	public static boolean isTesting = false;
	/* ============================ *
	 * ======DEBUGING=FUNCTIONS==== *
	 * ============================ */
	
	
	@SuppressWarnings("unused")
	private static void DEBUG_startAsConnectedUser(){
		loadingUI.hideLoadingScreen();
		Client testClient = new Client("alex", "a@f.c",dataManager);
		ClientUI clientUI= new ClientUI(testClient);
		clientUI.showMe();
		//System.exit(0);
	}

	
	@SuppressWarnings("unused")
	private static void initFromXml(){

		XmlBackup parser = new XmlBackup(STANDART_BACKUP_PATH);
		DataPackage pack = null;
		try {
			pack = parser.getCinemaData(false);
		} catch (XMLParsingException e) {
			e.printStackTrace();
		} catch (DataAccessException e) {
			e.printStackTrace();
		}

		parser.saveSites(pack.sites);
		parser.saveMovies(pack.movies);
	}
	
	/* =============================== *
	 * ===END=OF=DEBUGING=FUNCTIONS=== *
	 * =============================== */
	
	
	//fields
	public static IDataManager dataManager;
	private static LoadingUI loadingUI;

	/**
	 * Displays a connection screen to user.
	 */
	public static void showMainWindow(){
		ConnectionUI connectionUI= new ConnectionUI();
		connectionUI.showMe();
	}

	
	
	/**
	 * Main.
	 * You know what it does.
	 */
	public static void main(String[] args) {

		loadingUI = new LoadingUI();
		loadingUI.showLoadingScreen();
		dataManager = new DataManager(new XmlBackup(STANDART_BACKUP_PATH));
		//initFromXml();		

		//DEBUG_startAsConnectedUser();
		showMainWindow();

		loadingUI.hideLoadingScreen();

	}
	
	final private static String STANDART_BACKUP_PATH = ".\\backup";

}
